﻿using System.Collections.Generic;
using System.Linq;
using JStore.Core.Entities;
using SpeadFrm.ORM;

namespace JStore.Data.Daos
{
    /// <summary>
    ///
    /// </summary>
    public class MenusDao : BaseDao<Menus>
    {
        public List<Menus> GetAll()
        {
            var sql = Sql.Builder.OrderBy("SortOrder ASC");
            return Query(sql).ToList();
        }

        public List<Menus> GetParentList()
        {
            var sql = Sql.Builder.Where("ParentId = 0");
            return Query(sql).ToList();
        }

        public Menus GetByMenuId(int menuid)
        {
            var sql = Sql.Builder.Where("MenuId = @0", menuid);
            return FirstOrDefault(sql);
        }

        public void DeleteByMenuId(int menuId)
        {
            var sql = Sql.Builder.Where("MenuId = @0", menuId);
            Delete(sql);
        }

        public List<Menus> GetListByIds(List<int> menuIds)
        {
            var sql = Sql.Builder.Where("MenuId IN (@0)", menuIds);
            return Query(sql).ToList();
        }
    }
}

